<?php

//Load Master Page
require_once('../shared/layout.php');

//Load Shared Objects & Controls
require_once('../shared/alert.php');

class Index extends Layout {

    protected $objAlert, $mctContact;
    protected $txtStreet, $txtState, $txtCity, $txtZipcode, $txtNotes;
    protected $txtGoogleMapsUrl, $txtFlickrUrl, $txtFacebookUrl, $txtTwitterUrl, $txtSkypeUrl, $txtMsnUrl, $txtGooglePlusUrl;
    protected $btnSave;

    protected function Form_Create() {
        parent::Form_Create();

        $this->CssClass = 'form-horizontal';

        $this->strContextMenu = __DOCROOT__ . __SUBDIRECTORY__ . '/admin/view/contact/menu/index.tpl.php';

        $this->objAlert = new Alert($this);

        $this->mctContact = ContactMetaControl::CreateFromQueryString($this, QMetaControlCreateType::EditOnly);

        $this->txtStreet = $this->mctContact->txtStreet_Create();
        $this->txtState = $this->mctContact->txtState_Create();
        $this->txtCity = $this->mctContact->txtCity_Create();
        $this->txtZipcode = $this->mctContact->txtZipcode_Create();

        $this->txtNotes = $this->mctContact->txtNotes_Create();
        $this->txtNotes->TextMode = QTextMode::MultiLine;
        $this->txtNotes->Rows = 6;

        $this->txtGoogleMapsUrl = $this->mctContact->txtGoogleMapsUrl_Create();
        $this->txtFlickrUrl = $this->mctContact->txtFlickrUrl_Create();
        $this->txtFacebookUrl = $this->mctContact->txtFacebookUrl_Create();
        $this->txtTwitterUrl = $this->mctContact->txtTwitterUrl_Create();
        $this->txtSkypeUrl = $this->mctContact->txtSkypeUrl_Create();
        $this->txtMsnUrl = $this->mctContact->txtMsnUrl_Create();
        $this->txtGooglePlusUrl = $this->mctContact->txtGooglePlusUrl_Create();

        $this->btnSave = new QButton($this);
        $this->btnSave->Text = QApplication::Translate('Save Changes');
        $this->btnSave->PrimaryButton = $this->btnSave->CausesValidation = true;
        $this->btnSave->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnSave));
        $this->btnSave->AddAction(new QClickEvent(), new QAjaxAction('btnSave_Click'));
    }

    protected function btnSave_Click($strFormId, $strControlId, $strParameter) {
        try {
            $this->mctContact->Contact->LogUser = $this->objCurrentUser->Username;
            $this->mctContact->SaveContact();

            $this->objAlert->Success(QApplication::Translate('Success'), QApplication::Translate('Contact Info Saved Successful !'));
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            $this->objAlert->Error(QApplication::Translate('Ooops!'), $objExc->getMessage());
        }

        $this->btnSave->Enabled = true;
    }

}

Index::Run('Index', __DOCROOT__ . __SUBDIRECTORY__ . '/admin/view/contact/index.tpl.php');
?>